/*
    链表：
        

*/

function NodeList(val) {
    this.val = val;
    this.next = null;
};

// 数组转链表
function arrayToNodeList(list) {
    let header = new NodeList(0);
    let current = header;

    for (let i = 0; i < list.length; i++) {
        current.next = {
            val: list[i], 
            next: null
        };
        current = current.next;
    };

    return header.next;
};


// 链表转数组
function nodeListToArray(node) {
    let header = node;
    let arr = [];
    while (header) {
        arr.push(header.val);
        header = header.next;
    };
    return arr;
};


console.log(nodeListToArray(arrayToNodeList([1,2,3])))



